import { QuestionCircleFilled } from "@ant-design/icons"
import { Tooltip } from "antd"
import { ColumnGroupType, ColumnType } from "antd/es/table"
import dayjs from "dayjs"
import styled from "styled-components"

export const StyledParagraph = styled.p<{ $isCurved: boolean }>`
	color: ${props => props.color || ""}; /* Default color is black */
	${props => (props.$isCurved ? "background: rgba(0, 160, 0, 0.2);" : "")}
	${props => (props.$isCurved ? "width: 50px;" : "")}
	${props => (props.$isCurved ? "display: inline-block;" : "")}
	${props => (props.$isCurved ? "border-radius: 25px;" : "")}
`

export const renderNullableValue = (field: string, prefix = "", color = "", $isCurved = false) =>
	function ColorTableCell(_text: any, record: any) {
		const defaultPrefix = ""
		const defaultValue = ""
		return (
			<StyledParagraph color={color} $isCurved={$isCurved}>
				{!!record?.[field] && typeof record?.[field] === "number" && record?.[field] < 0 ? "-" : ""}
				{!!record?.[field] || record?.[field] === 0 ? prefix : defaultPrefix}
				{!!record?.[field] || record?.[field] === 0
					? typeof record[field] === "number"
						? Math.abs(record[field])
								.toString()
								.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
						: record[field]
					: defaultValue}
			</StyledParagraph>
		)
	}
const proxyReport = (newFormat: (arg: string) => string): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	monthProxyStatisticDate: {
		key: "statisticDate",
		dataIndex: "statisticDate",
		width: 120,
		render: (_text: any, record: any) => dayjs(String(record.staticsDate), "YYYYMMDD").format("YYYY-MM-DD"),
		title: newFormat("label.date"),
		align: "center",
		fixed: true
	},
	statisticDate: {
		key: "statisticDate",
		dataIndex: "statisticDate",
		width: 120,
		render: renderNullableValue("staticsDate"),
		title: newFormat("label.date"),
		align: "center",
		fixed: true
	},
	reportDate: {
		key: "reportDate",
		dataIndex: "reportDate",
		width: 120,
		render: renderNullableValue("reportDate"),
		title: newFormat("report.statistical_cycle"),
		align: "center",
		fixed: true
	},
	validBetRecalculationAdjustmentAmount: {
		key: "validBetRecalculationAdjustmentAmount",
		dataIndex: "validBetRecalculationAdjustmentAmount",
		title: newFormat("report.bet_recalculation"),
		width: 120,
		align: "center",
		sorter: (a, b) => a.validBetRecalculationAdjustmentAmount - b.validBetRecalculationAdjustmentAmount,
		render: renderNullableValue("validBetRecalculationAdjustmentAmount", "$")
	},
	realValidBetAmount: {
		key: "realValidBetAmount",
		dataIndex: "realValidBetAmount",
		title: newFormat("report.real_valid_bet_amount"),
		width: 120,
		align: "center",
		sorter: (a, b) => a.realValidBetAmount - b.realValidBetAmount,
		render: renderNullableValue("realValidBetAmount", "$")
	},
	serviceAmountContribution: {
		key: "serviceAmountContribution",
		dataIndex: "serviceAmountContribution",
		title: newFormat("report.service_amount_contribution"),
		width: 120,
		align: "center",
		sorter: (a, b) => a.serviceAmountContribution - b.serviceAmountContribution,
		render: renderNullableValue("serviceAmountContribution", "$")
	},
	proxyName: {
		key: "proxyName",
		dataIndex: "proxyName",
		width: 120,
		render: renderNullableValue("proxyName"),
		title: newFormat("label.agent_number"),
		align: "center",
		fixed: true
	},
	proxyLevel: {
		key: "proxyLevel",
		dataIndex: "proxyLevel",
		width: 120,
		render: renderNullableValue("proxyLevel"),
		title: newFormat("report.proxy_level"),
		align: "center",
		fixed: false
	},
	proxyAccountType: {
		key: "accountType",
		dataIndex: "accountType",
		width: 120,
		title: newFormat("report.account_type"),
		align: "center",
		fixed: false,
		render: (_text: any, record: any) => (
			<StyledParagraph $isCurved={false}>
				{newFormat(`label.member.${record.accountType === 1 ? "formal" : "failed"}`)}
			</StyledParagraph>
		)
	},
	parentProxyName: {
		key: "parentProxyName",
		dataIndex: "parentProxyName",
		width: 120,
		render: renderNullableValue("parentProxyName"),
		title: newFormat("report.parent_proxy"),
		align: "center",
		fixed: false
	},
	accountStatus: {
		key: "accountStatus",
		dataIndex: "accountStatus",
		width: 120,
		title: newFormat("report.account_status"),
		align: "center",
		fixed: false,
		render: (_text: any, record: any) => (
			<StyledParagraph color={record.loginLockStatus === 0 ? "green" : "red"} $isCurved={true}>
				{newFormat(`label.member.${record.loginLockStatus === 0 ? "success" : "failed"}`)}
			</StyledParagraph>
		)
	},
	windControlName: {
		key: "windControlName",
		dataIndex: "windControlName",
		width: 120,
		render: renderNullableValue("windControlName", "", ""),
		title: newFormat("report.wind_control_level"),
		align: "center",
		fixed: false
	},
	labelName: {
		key: "labelName",
		dataIndex: "labelName",
		width: 120,
		render: renderNullableValue("labelName", "", ""),
		title: newFormat("report.agent_tag"),
		align: "center",
		fixed: false
	},
	monthProxyBetAmount: {
		key: "betAmount",
		dataIndex: "betAmount",
		width: 150,
		render: renderNullableValue("betAmount", "$"),
		title: newFormat("report.total_bet_amount"),
		align: "center",
		fixed: false
	},
	betAmount: {
		key: "betAmount",
		dataIndex: "betAmount",
		width: 150,
		render: renderNullableValue("betAmount", "$"),
		title: newFormat("report.total_bet_amount"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.betAmount - b.betAmount
	},
	monthProxyProfitValidBetAmount1: {
		key: "validBetAmount",
		dataIndex: "validBetAmount",
		width: 150,
		render: renderNullableValue("validBetAmount", "$"),
		title: newFormat("report.total_valid_bet_amount"),
		align: "center",
		fixed: false
	},
	monthProxyProfitValidBetAmount: {
		key: "validBetAmount",
		dataIndex: "validBetAmount",
		width: 150,
		render: renderNullableValue("validBetAmount", "$"),
		title: newFormat("report.total_valid_bet_amount"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.validBetAmount - b.validBetAmount
	},
	memberCount: {
		key: "memberCount",
		dataIndex: "memberCount",
		width: 120,
		render: renderNullableValue("memberCount"),
		title: newFormat("report.member_count"),
		align: "center",
		fixed: false
	},
	gameMemberCount: {
		key: "memberCount",
		dataIndex: "memberCount",
		width: 120,
		render: renderNullableValue("memberCount"),
		title: newFormat("report.member_count"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.memberCount - b.memberCount
	},
	betCount: {
		key: "betCount",
		dataIndex: "betCount",
		width: 150,
		render: renderNullableValue("betCount"),
		title: newFormat("report.bet_count"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.betCount - b.betCount
	},
	gameBetCount: {
		key: "betCount",
		dataIndex: "betCount",
		width: 150,
		render: renderNullableValue("betCount"),
		title: newFormat("report.bet_count"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.betCount - b.betCount
	},
	monthProxyProfitBetCount: {
		key: "betCount",
		dataIndex: "betCount",
		width: 150,
		render: renderNullableValue("betCount"),
		title: newFormat("report.bet_count"),
		align: "center",
		fixed: false
	},
	monthProxyProfitNetAmount: {
		key: "netAmount",
		dataIndex: "netAmount",
		width: 150,
		render: renderNullableValue("netAmount", "$"),
		title: newFormat("report.member_total_wins"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.netAmount - b.netAmount
	},
	monthProxyProfitNetAmount1: {
		key: "netAmount",
		dataIndex: "netAmount",
		width: 150,
		render: renderNullableValue("netAmount", "$"),
		title: newFormat("report.member_total_wins"),
		align: "center",
		fixed: false
	},
	gameNetAmount: {
		key: "netAmount",
		dataIndex: "netAmount",
		width: 120,
		render: renderNullableValue("netAmount", "$"),
		title: newFormat("report.betting_profit_loss"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.netAmount - b.netAmount
	},
	gameRealNetAmount: {
		key: "realNetAmount",
		dataIndex: "realNetAmount",
		width: 120,
		render: renderNullableValue("realNetAmount", "$"),
		title: newFormat("report.game_real_net_amount"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.realNetAmount - b.realNetAmount
	},
	netRecalculationAdjustmentAmount: {
		key: "netRecalculationAdjustmentAmount",
		dataIndex: "netRecalculationAdjustmentAmount",
		width: 120,
		render: renderNullableValue("netRecalculationAdjustmentAmount", "$"),
		title: newFormat("report.net_recalculation_adjustment"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.netRecalculationAdjustmentAmount - b.netRecalculationAdjustmentAmount
	},
	monthProxyMemberRebateAmountByProxy: {
		key: "memberRebateAmountByProxy",
		dataIndex: "memberRebateAmountByProxy",
		width: 120,
		render: renderNullableValue("memberRebateAmountByProxy", "$"),
		title: newFormat("report.proxy_grant_member_rebate"),
		align: "center",
		fixed: false
	},
	memberRebateAmountByProxy: {
		key: "memberRebateAmountByProxy",
		dataIndex: "memberRebateAmountByProxy",
		width: 120,
		render: renderNullableValue("memberRebateAmountByProxy", "$"),
		title: newFormat("report.proxy_grant_member_rebate"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.memberRebateAmountByProxy - b.memberRebateAmountByProxy
	},
	monthProxyMemberRebateAmountByPlat: {
		key: "memberRebateAmountByPlat",
		dataIndex: "memberRebateAmountByPlat",
		width: 120,
		render: renderNullableValue("memberRebateAmountByPlat", "$"),
		title: newFormat("report.platform_grant_member_rebate"),
		align: "center",
		fixed: false
	},
	memberRebateAmountByPlat: {
		key: "memberRebateAmountByPlat",
		dataIndex: "memberRebateAmountByPlat",
		width: 120,
		render: renderNullableValue("memberRebateAmountByPlat", "$"),
		title: newFormat("report.platform_grant_member_rebate"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.memberRebateAmountByPlat - b.memberRebateAmountByPlat
	},
	serviceChargeRound: {
		key: "serviceChargeRound",
		dataIndex: "serviceChargeRound",
		width: 120,
		render: renderNullableValue("serviceChargeRound", "$"),
		title: () => (
			<Tooltip title={newFormat("report.service_charge_round_tips")}>
				{newFormat("report.service_charge_round")}
				<QuestionCircleFilled />
			</Tooltip>
		),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.serviceChargeRound - b.serviceChargeRound
	},
	valueAddedTotalAmount: {
		key: "valueAddedTotalAmount",
		dataIndex: "valueAddedTotalAmount",
		width: 120,
		render: renderNullableValue("valueAddedTotalAmount", "$"),
		title: () => (
			<Tooltip title={newFormat("report.value_added_total_tips")}>
				{newFormat("report.value_added_total")}
				<QuestionCircleFilled />
			</Tooltip>
		),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.valueAddedTotalAmount - b.valueAddedTotalAmount
	},
	memberArtificialPatchAmount: {
		key: "memberArtificialPatchAmount",
		dataIndex: "memberArtificialPatchAmount",
		width: 120,
		render: renderNullableValue("memberArtificialPatchAmount", "$"),
		title: newFormat("report.other_adjustments"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.memberArtificialPatchAmount - b.memberArtificialPatchAmount
	},
	monthProxyMemberArtificialPatchAmount: {
		key: "memberArtificialPatchAmount",
		dataIndex: "memberArtificialPatchAmount",
		width: 120,
		render: renderNullableValue("memberArtificialPatchAmount", "$"),
		title: newFormat("report.month_proxy_member_artificial"),
		align: "center",
		fixed: false
	},
	memberNetwinAmount: {
		key: "memberNetwinAmount",
		dataIndex: "memberNetwinAmount",
		width: 120,
		render: renderNullableValue("memberNetwinAmount", "$"),
		title: () => (
			<p>
				{newFormat("report.member_net_profit")}
				<Tooltip title={newFormat("report.member_net_profit_tips")}>
					<QuestionCircleFilled />
				</Tooltip>
			</p>
		),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.memberNetwinAmount - b.memberNetwinAmount
	},
	monthProxyMemberNetwinAmount: {
		key: "memberNetwinAmount",
		dataIndex: "memberNetwinAmount",
		width: 120,
		render: renderNullableValue("memberNetwinAmount", "$"),
		title: newFormat("report.month_proxy_member_netwin_amount"),
		align: "center",
		fixed: false
	},
	directBetAmount: {
		key: "directBetAmount",
		dataIndex: "directBetAmount",
		width: 120,
		render: renderNullableValue("directBetAmount", "$"),
		title: newFormat("report.direct_bet_amount"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directBetAmount - b.directBetAmount
	},
	directValidBetAmount: {
		key: "directValidBetAmount",
		dataIndex: "directValidBetAmount",
		width: 120,
		render: renderNullableValue("directValidBetAmount", "$"),
		title: newFormat("report.direct_valid_bet_amount"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directValidBetAmount - b.directValidBetAmount
	},
	directNetAmount: {
		key: "directNetAmount",
		dataIndex: "directNetAmount",
		width: 120,
		render: renderNullableValue("directNetAmount", "$"),
		title: newFormat("report.direct_member"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directNetAmount - b.directNetAmount
	},
	directMemberRebateAmountByProxy: {
		key: "directMemberRebateAmountByProxy",
		dataIndex: "directMemberRebateAmountByProxy",
		width: 120,
		render: renderNullableValue("directMemberRebateAmountByProxy", "$"),
		title: newFormat("report.direct_member_rebate_by_proxy"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directMemberRebateAmountByProxy - b.directMemberRebateAmountByProxy
	},
	directMemberRebateAmountByPlat: {
		key: "directMemberRebateAmountByPlat",
		dataIndex: "directMemberRebateAmountByPlat",
		width: 120,
		render: renderNullableValue("directMemberRebateAmountByPlat", "$"),
		title: newFormat("report.direct_member_rebate_by_plat"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directMemberRebateAmountByPlat - b.directMemberRebateAmountByPlat
	},
	directArtificialPatchAmount: {
		key: "directArtificialPatchAmount",
		dataIndex: "directArtificialPatchAmount",
		width: 120,
		render: renderNullableValue("directArtificialPatchAmount", "$"),
		title: newFormat("report.direct_member_other_ajustment"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directArtificialPatchAmount - b.directArtificialPatchAmount
	},
	directNetwinAmount: {
		key: "directNetwinAmount",
		dataIndex: "directNetwinAmount",
		width: 120,
		render: renderNullableValue("directNetwinAmount", "$"),
		title: () => (
			<p>
				{newFormat("report.direct_profit_amount")}
				<Tooltip title={newFormat("report.direct_profit_amount_tips")}>
					<QuestionCircleFilled />
				</Tooltip>
			</p>
		),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directNetwinAmount - b.directNetwinAmount
	},
	directNetwinAmountMonth: {
		key: "directNetwinAmount",
		dataIndex: "directNetwinAmount",
		width: 120,
		render: renderNullableValue("directNetwinAmount", "$"),
		title: () => <p>{newFormat("report.direct_profit_amount")}</p>,
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directNetwinAmount - b.directNetwinAmount
	},
	loginLockStatus: {
		key: "loginLockStatus",
		dataIndex: "loginLockStatus",
		width: 120,
		title: newFormat("report.account_status"),
		align: "center",
		fixed: false,
		render: (_text: any, record: any) => (
			<StyledParagraph color={record.loginLockStatus === 0 ? "green" : "red"} $isCurved={true}>
				{newFormat(`label.member.${record.loginLockStatus === 0 ? "success" : "failed"}`)}
			</StyledParagraph>
		)
	},
	proxyRebatePoint: {
		key: "proxyRebatePoint",
		dataIndex: "proxyRebatePoint",
		width: 120,
		render: renderNullableValue("proxyRebatePoint", "$"),
		title: newFormat("report.agent_rebate"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.proxyRebatePoint - b.proxyRebatePoint
	},
	proxyArtificialPatchAmount: {
		key: "proxyArtificialPatchAmount",
		dataIndex: "proxyArtificialPatchAmount",
		width: 120,
		render: renderNullableValue("proxyArtificialPatchAmount", "$"),
		title: newFormat("report.agent_other_adjust"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.proxyArtificialPatchAmount - b.proxyArtificialPatchAmount
	},
	venueFee: {
		key: "venueFee",
		dataIndex: "venueFee",
		width: 120,
		render: renderNullableValue("venueFee", "$"),
		title: newFormat("report.member_venue_amount"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.venueFee - b.venueFee
	},
	proxyNetwinAmount: {
		key: "proxyNetwinAmount",
		dataIndex: "proxyNetwinAmount",
		width: 120,
		render: renderNullableValue("proxyNetwinAmount", "$"),
		title: newFormat("report.proxy_net"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.proxyNetwinAmount - b.proxyNetwinAmount
	},
	lastMonthBalance: {
		key: "lastMonthBalance",
		dataIndex: "lastMonthBalance",
		width: 120,
		render: renderNullableValue("lastMonthBalance", "$"),
		title: newFormat("report.last_period_balance"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.lastMonthBalance - b.lastMonthBalance
	},
	proxyRushNet: {
		key: "proxyRushNet",
		dataIndex: "proxyRushNet",
		width: 120,
		render: renderNullableValue("proxyRushNet", "$"),
		title: newFormat("report.proxy_reversing_net_losses"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.proxyRushNet - b.proxyRushNet
	},
	monthProxyDirectRebateAmountByProxy: {
		key: "directMemberRebateAmountByProxy",
		dataIndex: "directMemberRebateAmountByProxy",
		width: 120,
		render: renderNullableValue("directMemberRebateAmountByProxy", "$"),
		title: newFormat("report.direct_member_rebate_by_proxy"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directMemberRebateAmountByProxy - b.directMemberRebateAmountByProxy
	},
	monthProxyDirectRebateAmountByPlat: {
		key: "directMemberRebateAmountByPlat",
		dataIndex: "directMemberRebateAmountByPlat",
		width: 120,
		render: renderNullableValue("directMemberRebateAmountByPlat", "$"),
		title: newFormat("report.direct_member_rebate_by_plat"),
		align: "center",
		fixed: false,
		sorter: (a, b) => a.directMemberRebateAmountByPlat - b.directMemberRebateAmountByPlat
	}
})

export default proxyReport
